package dryven.sapi.jetty;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.component.LifeCycle.Listener;

public class JettyServer {
	
	private int _port = 8080;
	private Server _server;
	
	public JettyServer(int port) {
		_port = port;
	}
	
	public void start() throws Exception {
		_server = setupServer();
		_server.start();
	}
	
	public void join() throws InterruptedException {
		_server.join();
	}
	
	private Server setupServer() {
		Server server = new Server(_port);
		server.setHandler(new JettyHandler());
		return server;
	}
	
	public String getRootURL() {
		return "http://localhost:"+_port+"/";
	}
}
